package com.gitee.ice1938.module.admin.sysoption.fun;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class OptionController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = LoggerFactory.getLogger(OptionController.class);

	@Autowired
	private OptionService optionService;
	@Autowired
	private CacheManager cacheManager;

	@RequestMapping(path = "/admin/sys_option", method = RequestMethod.GET)
	public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
		Collection<String> list = cacheManager.getCacheNames();
		List<Map<String, Object>> cdata = new ArrayList<Map<String, Object>>();
		for (String item : list) {
			Cache cache = cacheManager.getCache(item);
			Object obj = cache.getNativeCache();
			if (obj instanceof javax.cache.Cache) {
				javax.cache.Cache c = (javax.cache.Cache) obj;
				Map e = new HashMap<String, Object>();
				e.put("name", item);
				e.put("size", 0);
				cdata.add(e);
			}
		}
		model.addAttribute("cacheInfo", cdata);
		List<Map<String, Object>> data = optionService.findOptions();
		model.addAttribute("options", data);
		return "module/admin/sysoption/view_list";
	}

}
